#include <vector_types.h>
#include <cutil_inline.h>
#include "psoml_kernel.c"

extern "C" void NeighbourMax(dim3 blockSize, dim3 gridSize, float* likelihood, float* likelihoodBest, int* neighbourhood, int neighbourhoodSize, int* neighbourhoodBest, pNode* pNodeArray, int treeLength){
	NeighbourMax_Kernel<<<gridSize, blockSize>>>(likelihood, likelihoodBest, neighbourhood, neighbourhoodSize, neighbourhoodBest, pNodeArray, treeLength);
	CUT_CHECK_ERROR("Kernel execution failed\n");
	CUDA_SAFE_CALL( cudaThreadSynchronize() );
}

extern "C" void UpdateLengthDeltas(dim3 blockSize, dim3 gridSize, pNode* pNodeArray, int treeLength, int* globalBest, int* neighbourhoodBest, float4 swarmConstants, float3 randomVectors){
	UpdateLengthDeltas_Kernel<<<gridSize, blockSize>>>(pNodeArray, treeLength, globalBest, neighbourhoodBest, swarmConstants, randomVectors);
	CUT_CHECK_ERROR("Kernel execution failed\n");
	CUDA_SAFE_CALL( cudaThreadSynchronize() );
}

extern "C" void EvaluateParticles(dim3 blockSize, dim3 gridSize, cNode* nodeArray, int treeLength, pNode* pNodeArray, float* priorProbability, float* likelihood){
	EvaluateParticles_Kernel<<<gridSize, blockSize, treeLength * sizeof(cNode)>>>(nodeArray, treeLength, pNodeArray, priorProbability, likelihood);
	CUT_CHECK_ERROR("Kernel execution failed\n");
	CUDA_SAFE_CALL( cudaThreadSynchronize() );
}

extern "C" void Maximum(dim3 gridSize, dim3 blockSize, float* likelihoods, int* maxIdx){
	Maximum_Kernel<<<gridSize, blockSize>>>(likelihoods, maxIdx);
	CUT_CHECK_ERROR("Kernel execution failed\n");
	CUDA_SAFE_CALL( cudaThreadSynchronize() );
}